{include file="header/index" /}
<meta charset="UTF-8">
		<!--导航结束-->
		<div class="container whitebg">
			<!-- Nav tabs -->
			<ul class="nav nav-tabs" role="tablist">
				<li><i class="glyphicon glyphicon-menu-hamburger" style="margin-top: 13px;"></i></li>
				<li role="presentation" class="active">
					<a href="#All" aria-controls="All" onclick="getk(0)" role="tab" data-toggle="tab">全部</a>
					<span class="fr">|</span>
				</li>
				<!--将工单类型循环取出-->
				{foreach $type as $k => $v}
				<li role="presentation">
					<a href="#install" aria-controls="install" id="type_{$k}" class="qieh{$k}" onclick="getk({$k})" role="tab" data-toggle="tab" data-status="{$k}">{$v}</a>
					<span class="fr">|</span>
				</li>
				{/foreach}

				<!--隐藏域，用来装工单类型id-->
				<input type="hidden" name="status" value="0" />

			</ul>


			<!--模糊搜索-->
			<form class="form-inline mt20 mb20" action="" method="post">
				<div class="form-group">
					<label>下单时间</label>
					<input class="form-control input-time" type="text" id="datetimeStart" readonly class="form_datetime">
					<input class="form-control input-time" type="text" id="datetimeEnd" readonly class="form_datetime">
				</div>

				<div class="form-group ml20">
					<label>业务类型</label>
					<select id="type" class="form-control input-min">
						<option value="" selected="selected">请选择</option>
						{foreach $workType as $k=>$v}
						<option value="{$k}">{$v}</option>
						{/foreach}
					</select>
				</div>

					<div class="form-group ml20">
					<label>处理状态</label>
					<select id="workStatus" class="form-control input-min">
				{if condition='($groupDataId == 4)'}
						{if condition='($workorderstatus == 3)'}
						<option value="" selected="selected">请选择处理状态</option>
						<option value="5">工程部未指派工程人员</option>
						<option value="7">工程人员未接单</option>
						{else /}
						<option value="" selected="selected">请选择处理状态</option>
						<option value="7">工程人员未接单</option>
						<option value="8">工程人员服务中</option>
						<option value="9">工程人员已完成</option>
						<option value="13">已完成</option>
						{/if}
				{/if}
				{if condition='($groupDataId == 5)'}
						{if condition='($workorderstatus == 3)'}
						<option value="" selected="selected">请选择处理状态</option>
						<option value="7">工程人员未接单</option>
						<option value="8">工程人员服务中</option>
						<option value="9">工程人员已完成</option>
						{else /}
						<option value="" selected="selected">请选择处理状态</option>
						<option value="7">工程人员未接单</option>
						<option value="8">工程人员服务中</option>
						<option value="9">工程人员已完成</option>
						<option value="13">已完成</option>
						{/if}
				{/if}
				{if condition='($groupDataId == 1)'}
						{if condition='($workorderstatus == 3)'}
						<option value="" selected="selected">请选择处理状态</option>
						<option value="1">无效</option>
						<option value="2">前台未处理</option>
						<option value="3">前台已确认</option>
						{else /}
						<option value="" selected="selected">请选择处理状态</option>
						<option value="5">工程部未指派工程人员</option>
						<option value="7">工程人员未接单</option>
						<option value="8">工程人员服务中</option>
						<option value="9">工程人员已完成</option>
						<option value="10">前台未回访</option>
						<option value="11">前台已回访，未完成</option>
						<option value="12">前台已回访，已完成</option>
						<option value="13">已完成</option>
						{/if}
				{/if}
				{if condition='($groupDataId == 2)'}
						{if condition='($workorderstatus == 3)'}
						<option value="" selected="selected">请选择处理状态</option>
						<option value="1">无效</option>
						<option value="2">前台未处理</option>
						<option value="3">前台已确认</option>
						{else /}
						<option value="" selected="selected">请选择处理状态</option>
						<option value="5">工程部未指派工程人员</option>
						<option value="7">工程人员未接单</option>
						<option value="8">工程人员服务中</option>
						<option value="9">工程人员已完成</option>
						<option value="10">前台未回访</option>
						<option value="11">前台已回访，未完成</option>
						<option value="12">前台已回访，已完成</option>
						<option value="13">已完成</option>
						{/if}
				{/if}
					</select>
					</div>
				<br />
				<div class="form-group mr20 mt10">
					<input type="text" class="form-control input-min" id="order_number" placeholder="请输入工单号">
				</div>
				<div class="form-group mr20 mt10">
					<input type="text" class="form-control input-min" id="username" placeholder="请输入户名">
				</div>
				<div class="form-group mr20 mt10">
					<input type="text" class="form-control input-min" id="telphone" placeholder="请输入联系电话">
				</div>
				<div class="form-group mr20 mt10">
					<input type="text" class="form-control input-min" id="engineers_name" placeholder="请输入工程人员">
				</div>
				<div class="form-group mr20 mt10">
					<input type="text" class="form-control input-min" id="engineers_number" placeholder="请输入工程编号">
				</div>

				<input type="hidden" id="UpdateTime" value="">

				<button type="button" id="search" class="btn btn-default input-Btn mt10">搜索</button>
				<button type="button" class="btn btn-primary fr input-Btn mt10" onclick="window.location.href='/administrative/workorder/workorderadd'"><i class="glyphicon glyphicon-plus"></i>
					&nbsp;&nbsp;新增工单</button>
			</form>


			<!-- Tab panes -->
			<div class="tab-content">
				<!--全部-->
				<div role="tabpanel" class="tab-pane active" id="Alll">

					<table class="table table-bordered">
						<tr>
							<th><input type="checkbox" onclick="checkAll(this,'box')" id="all" /></th>
							<th>工单号</th>
							<th>户名</th>
							<th>联系电话</th>
							<th>业务类型</th>
							<th>服务地址</th>
							<th>金额</th>
							<th>下单时间</th>
							<th>换芯时间</th>
							<th>续费周期</th>
							<th>处理状态</th>
							<th>工程人员</th>
							<th>操作</th>
						</tr>

						<!--字符串拼接-->
						<tbody id="list">
						{volist name="data" id="k"}
							{if condition="($k.audit_status == 1)"}
								<tr style="background-color: #5FB878 !important;">
							{elseif condition="$k.audit_status == 2"/}
								<tr style="background-color: red !important;">
							{else /}
								<tr>
							{/if}
							<td style="background-color: red"><input class="selectthis" type="checkbox" value="{$k.work_order_id}" name="box" onclick="selectAll('box','all')" /></td>
							<td style="background-color: red">{$k.order_number} </td>
							<td style="background-color: red">{$k.username}</td>
							<td style="background-color: red">{$k.telphone}</td>
							<td style="background-color: red">{$k.business_id}</td>
							<td style="background-color: red">
								<p  class="ellipsis" style="width:130px">{$k.service_address}</p>
							</td>
							<td>￥{$k.combo_money}元</td>
							<td>{$k.order_time}</td>
							<td>{$k.for_core_time}</td>
							<td>{$k.renew_date}</td>
							<td onclick="usrePopup({$k.work_order_id})">
								<span class="selecttxt cursor col-127">{$k.work_order_status}</span>
							</td>
							<td>{$k.engineers_name}</td>
							<td>
								<a href="#">查看</a>
								<a href="#">修改</a>
							</td>
						</tr>
						{/volist}
						</tbody>

						<input type="hidden" value="" name="workOrderStatus" />
					</table>

				{if condition='($workorderstatus == 3)'}
					{if condition='($groupDataId == 2)'}
						<button class="btn btn-default bluecolor" onclick="EngineeringDepartment()">指派工程部</button>
					{/if}
					{if condition='($groupDataId == 4)'}
						<button class="btn btn-default bluecolor ml20" onclick="AssignEngineer()">指派工程人员</button>
					{/if}
					{if condition='($groupDataId == 1)'}
						<button class="btn btn-default bluecolor" onclick="EngineeringDepartment()">指派工程部</button>
						<button class="btn btn-default bluecolor ml20" onclick="Batchconfirmation()">确认工单</button>
					{/if}
				{/if}
				{if condition='($workorderstatus == 4)'}
					{if condition='($groupDataId == 1)'}
					<!--<button class="btn btn-default bluecolor" onclick="EngineeringDepartment()">指派工程部</button>-->
					<button class="btn btn-default bluecolor ml20" onclick="AssignEngineer()">指派工程人员</button>
					{/if}
				{/if}
					<!--分页-->
					<!--指派工程人员结果存放-->
					<input type="hidden" value="" name="assignEngineers" />
				</div>
			</div>

			 <!--用来装是未指派还是已指派对应值，用于修改状态时判断-->
			<input type="hidden" value="{$workorderstatus}" name="workorderstatus" />
			<!--用来装哪个角色登录的-->
			<input type="hidden" value="{$groupDataId}" name="groupDataId" />
			<span><i style="width: 12px;background: #FFFFFF">&nbsp;&nbsp;&nbsp;&nbsp;</i>：无色代表待审核</span>
			<span><i style="width: 12px;background: #5FB878">&nbsp;&nbsp;&nbsp;&nbsp;</i>：绿色代表审核通过</span>
			<span><i style="width: 12px;background: red">&nbsp;&nbsp;&nbsp;&nbsp;</i>：红色代表审核未通过</span>
			<!--分页显示-->
			<div class="clearfix" style="float:right;margin: 0 auto;">
				<span class="fl mt5">共<b id="total">{$count}</b>条数据</span><span id="allpage" class="fl  mr20 mt5"></span><span class="fl" id="AjaxPage"></span>
			</div>
			<!-- 加载动画 -->
			<div class="spiner-example">
				<div class="sk-spinner sk-spinner-three-bounce">
					<div class="sk-bounce1"></div>
					<div class="sk-bounce2"></div>
					<div class="sk-bounce3"></div>
				</div>
			</div>
		</div>

		
	</body>
<script>

	/*
	 *操作台传值过来
	 */
    //--------------------------------------start---------------------------------------
    var assigned = $("#assigned", window.parent.document).val();
    var startUpdateTime = $("#startUpdateTime", window.parent.document).val();
    if (startUpdateTime != 'yes'){
        $("#UpdateTime").val(startUpdateTime);
    }
    if (assigned == 'yes'){
        $("#MenuShowList li:eq(1)", window.parent.document).click();
        var work_order_type = $("#work_order_type", window.parent.document).val();
        if (work_order_type != ''){
            $("#type_"+work_order_type).click();
            var work_order_status = $("#work_order_status", window.parent.document).val();
            $("#workStatus").val(work_order_status);
            $("#search", window.parent.document).click();
            startUpdateTime = '';
            $("#assigned", window.parent.document).val('');
        }
    }
    if (assigned == 'no'){
        $("#MenuShowList li:eq(0)", window.parent.document).click();
        var work_order_type = $("#work_order_type", window.parent.document).val();
        if (work_order_type != ''){
            $("#type_"+work_order_type).click();
            var work_order_status = $("#work_order_status", window.parent.document).val();
            $("#workStatus").val(work_order_status);
            $("#search", window.parent.document).click();
            startUpdateTime = '';
            $("#assigned", window.parent.document).val('');
        }
    }
    //--------------------------------------end---------------------------------------


    //处理工程人员传输显示订单
    var gcry = $("#gcry", window.parent.document).val();
    var status = $("#gstatus", window.parent.document).val();
    $("#engineers_number").val(gcry);
    if(status == 13){
        $("#workStatus option[value='13']").attr("selected","selected");
        $("#gcry", window.parent.document).val('');
    }
    if(status == 8){
        $("#workStatus option[value='8']").attr("selected","selected");
        $("#gcry", window.parent.document).val('');

    }

    //修改状态信息
    function usrePopup(id){
        var workorderstatus = $("input[name='workorderstatus']").val();
        var group_obj = $("input[name='groupDataId']").val();
        // 发送ajax请求获取备注信息
        $.getJSON("{:url('/administrative/workorder/getremarks')}",{work_order_id:id},function(data){
            // 获取工单类型配置信息，转换为对象
            var status_obj=<?php  echo json_encode($work_order_status); ?>;
            var status_arr = eval(status_obj);
            var str = "";

			if(group_obj == 1 && {$workorderstatus} == 3){
			// 超管未指派
                str += "<option value=1>无效</option>";
                str += "<option value=2>前台未处理</option>";
                str += "<option value=3>前台已确认</option>";
			// 超管已指派
            }else if(group_obj == 1 && {$workorderstatus} == 4){
                str += "<option value=1>无效</option>";
                str += "<option value=2>前台未处理</option>";
                str += "<option value=3>前台已确认</option>";
                str += "<option value=5>工程部未指派工程人员</option>";
                str += "<option value=7>工程人员未接单</option>";
                str += "<option value=8>工程人员服务中</option>";
                str += "<option value=9>工程人员已完成</option>";
                str += "<option value=10>前台未回访</option>";
                str += "<option value=11>前台已回访，未完成</option>";
                str += "<option value=12>前台已回访，已完成</option>";
			// 前台未指派
            }else if(group_obj == 2 && {$workorderstatus} == 3){
                str += "<option value=1>无效</option>";
                str += "<option value=2>前台未处理</option>";
                str += "<option value=3>前台已确认</option>";
			// 前台已指派
            }else if(group_obj == 2 && {$workorderstatus} == 4 && data[0].work_order_status > 6){
//                if(data[0].work_order_status < 4 && data[0].work_order_status != 1){
//                    str += "<option value=1>无效</option>";
//                }
                for(var i=data[0].work_order_status+1;i<=getJsonLength(status_arr);i++){
                    str +="<option value="+i+">"+status_arr[i]+"</option>";
                }
			// 工程人员未指派
            }else if(group_obj == 5 && {$workorderstatus} == 3){
                str += "<option value=8>工程人员服务中</option>";
                str += "<option value=9>工程人员已完成</option>";
			// 工程人员已指派
            }else if(group_obj == 5 && {$workorderstatus} == 4){
                str += "<option value=9>工程人员已完成</option>";
            }

			var html ='<div class="stateWorkorder">';
            html +='<div>';
            html +='<p class="clearfix">';
            html +='<label class="fl">处理状态</label>';
            html +='<select id="_orderStatus'+id+'">';
            html +='<option value="">选择状态</option>';
            html +=str;
            html +='</select>';
            html +='</p>';
            html +='<p class="clearfix">';
            html +='<label  class="fl">备注</label>';
            html +='<textarea id="remarks'+id+'"></textarea>';
            html +='</p>';
            html +='<p class="state-Btn">';
            html +='<button onclick="savesuccess('+id+','+workorderstatus+')" type="button" class="btn btn-primary">保存</button>';
            html +='<button onclick="layuihide()" type="button" class="btn btn-default">取消</button>	';
            html +='</p>';
            html +='<ul class="">';
            $.each(data,function(k,v){
            html +='<li class="clearfix">';
			html +='<span class="state-lis-left fl ellipsis">' + v.remarks + '</span>';
			html +='<span class="state-lis-left fr ">备注人：'+ v.username +'  时间：' + v.operating_time + '</span>';
            html +='</li>';
            });
            html +='</ul>';
            html +='</div>';
            html +='</div>';
            html +='<input name="workOrderStatus'+id+'" value="'+id+'" type="hidden">';
            top.layer.open({
                type: 1,
                title: '处理状态',
                skin: 'layui-layer-demo', //样式类名
                closeBtn: 0, //不显示关闭按钮
                anim: 2,
                area: ['600px', '420px'], //宽高
                shadeClose: true, //开启遮罩关闭
                content:html
            });
        });
    }

    // 计算json对象长度
    function getJsonLength(jsonData){
        var jsonLength = 0;
        for(var item in jsonData){
            jsonLength++;
        }
        return jsonLength;
    }


    // 模糊搜索按钮点击事件
    $("#search").click(function() {
        // 获取工单类型隐藏域对应的值
        var workType = $("input[name='status']").val();

        // 清楚  全部按钮 的class样式
        $("#remclass>li").removeClass('active');
        // 给搜索的工单类型加入class
        $("#qie" + workType).parent('li').addClass('active');

        // 调用分页
        //            Ajaxpage(startTime,endTime,order_number,username,contract_no,workStatus,province,city,area);
        Ajaxpage();
    });


    // 工单类型切换
    function getk(id) {
        //清空checkbox
        $("input[type=checkbox]").prop("checked", false);
        // 清空搜索数据
        $("#datetimeStart").val('');
        $("#datetimeEnd").val('');
        $("#order_number").val('');
        $("#username").val('');
        $("#telphone").val('');
        $("#engineers_name").val('');
        $("#engineers_number").val('');
        $("#workStatus").val('');
        $("#type").val('');
        $("#_province").val('');
        $("#_city").val('');
        $("#_area").val('');

        // 将id存入隐藏域
        $("input[name='status']").val(id);

        // 调用分页
        Ajaxpage();
    }


    //laypage分页
    Ajaxpage();
    // curr 获取当前页面数
    function Ajaxpage(curr) {
        // 获取模糊搜索数据
        var startTime = $("#datetimeStart").val();
        var endTime = $("#datetimeEnd").val();
        var order_number = $("#order_number").val();
        var username = $("#username").val();
        var telphone = $("#telphone").val();
        var engineers_name = $("#engineers_name").val();
        var engineers_number = $("#engineers_number").val();
        var workStatus = $("#workStatus").val();
        var type = $("#type").val();
        var startUpdateTime = $("#UpdateTime").val();
        var endUpdateTime = $("#UpdateTime").val();
        var key = $('#key').val();
        // 获取隐藏域里面的类型对应数字
        var status = $('input[name="status"]').val();
        // 发送ajax请求
        $.getJSON('{:url("workorder/index")}', {
            page: curr || 1,
            key: key,
            status: status,   					// 工单业务类型切换
            startTime: startTime,  				// 下单开始时间
            endTime: endTime,      				// 下单结束时间
            order_number: order_number,    		// 工单编号
            username: username,					// 用户名
            telphone: telphone,					// 联系电话
            engineers_name: engineers_name,  	// 工程人员
            engineers_number: engineers_number, // 工程人员编号
            workStatus: workStatus,				// 处理状态
            type: type,							// 业务类型
            startUpdateTime: startUpdateTime,
			endUpdateTime: endUpdateTime,
            workorderstatus:{$workorderstatus}  // 判断是否是续费跟换芯
        }, function(data) {
							//	console.log(data);
            $(".spiner-example").css('display', 'none'); //数据加载完关闭动画
            if(data == '') {
                // 替换总的数据
                document.getElementById('total').innerText = 0;
                $("#list").html('<td colspan="20" style="padding-top:10px;padding-bottom:10px;font-size:16px;text-align:center">暂无数据</td>');
            } else {
                // 替换总的数据
                document.getElementById('total').innerText = data[0].count;
                // 清空数据
                $("#list").html('');
                // 将数据循环，拼接
                var str = '';
                $.each(data, function(key, val) {
                    var engineers_name= val.engineers_name==null ? '未指派' : val.engineers_name;

                    if (val.audit_status == 1){
                        str += '<tr style="background-color: #5FB878 !important;">';
                    } else if (val.audit_status == 2 && val.order_status == 12){
                        str += '<tr style="background-color: red !important;">';
                    } else {
                        str += '<tr>';
                	}
                    str += '<td><input class="selectthis" type="checkbox" value=' + val.work_order_id + ' name="box" onclick="selectAll(' + "'box'" + ',' + "'all'" + ')"/></td>';
                    str += '<td>' + val.order_number + '</td>';
                    str += '<td>' + val.username + '</td>';
                    str += '<td>' + val.telphone + '</td>';
                    str += '<td>' + val.business_id + '</td>';
                    str += '<td>' + val.service_address + '</td>';
                    str += '<td>'+"￥" + val.combo_money + "元" + '</td>';
                    str += '<td>' + val.order_time + '</td>';
                    str += '<td>' + val.for_core_time + '</td>';
                    str += '<td>' + val.renew_date + '</td>';
                    str += '<td onclick="usrePopup(' + val.work_order_id + ')">';
                    str += '<span class="selecttxt cursor col-127">' + val.work_order_status + '</span>';
                    str += '<td>' + engineers_name + '</td>';
                    str += '<td>';
                    str += '<a href="/administrative/workorder/detail?id=' + val.work_order_id + '">查看</a>&nbsp;';
                    str += '<a href="/administrative/workorder/edit/wid/'+val.work_order_id+'/uid/'+val.user_id+'/cid/'+val.contract_id+'/who/'+ val.renewcore +'">修改</a>';
                    str += '</td>';
                    str += '</tr>';
                });
                // 将拼接的数据输出在页面
                $("#list").html(str);

                laypage({
                    cont: $('#AjaxPage'), //容器。值支持id名、原生dom对象，jquery对象,
                    pages: data[0].allPage, //总页数
                    skip: true, //是否开启跳页
                    skin: '#337ab7', //分页组件颜色
                    curr: curr || 1,
                    first: '首页', //若不显示，设置false即可
                    last: '尾页', //若不显示，设置false即可
                    groups: 3, //连续显示分页数
                    jump: function(obj, first) {
                        if(!first) {
                            Ajaxpage(obj.curr)
                        }
                        $('#allpage').html('，第'+ obj.curr +'页，共'+ '<i>'+obj.pages+'</i>' +'页');
						inputlength();
                    }
                });
            }
        });
    }
</script>

</html>

<script type="text/javascript">

    //复选框选中
    function checkAll(obj, name) {
        //alert(obj.checked);
        //获取name=box的复选框
        var userids = document.getElementsByName(name);
        //alert(userids.length);
        for(var i = 0; i < userids.length; i++) {
            userids[i].checked = obj.checked;
        }
    }

    function selectAll(name, id) {
        //获取name=box的复选框
        var userids = document.getElementsByName(name);
        var count = 0;
        //遍历所有的复选框
        for(var i = 0; i < userids.length; i++) {
            if(userids[i].checked) {
                count++;
            }
        }
        //选中复选框的个数==获取复选框的个数
        if(count == userids.length) {
            //设置id为all复选框选中
            document.getElementById(id).checked = true;
        } else {
            //设置id为all复选框不选中
            document.getElementById(id).checked = false;
        }
    }



	function selectstate(obj){
		var txt=$(obj).text();
		$(obj).parents('.selectstate').find('.selecttxt').text(txt);
		$(obj).parents('.selectlist').removeClass('show').addClass('hide');		
	}

	//日期选择
	$("#datetimeStart").datetimepicker({
		language: 'cn',
		format: "yyyy-mm-dd",
		autoclose: true,
		minView: "month",
		maxView: "decade",
		todayBtn: true,
		pickerPosition: "bottom-left"
	}).on("click", function(ev) {
		$("#datetimeStart").datetimepicker("setEndDate", $("#datetimeEnd").val());
	});
	$("#datetimeEnd").datetimepicker({
		language: 'cn',
		format: "yyyy-mm-dd",
		autoclose: true,
		minView: "month",
		maxView: "decade",
		todayBtn: true,
		pickerPosition: "bottom-left"
	}).on("click", function(ev) {
		$("#datetimeEnd").datetimepicker("setStartDate", $("#datetimeStart").val());
	});
	//model高度自适应
	$(document).ready(function() {
		var height = $(window).height() - 120;
		$(".model_contract").css("height", height * 0.9)
	});



    // 前台批量确认
    function Batchconfirmation() {
        if($('.selectthis').is(':checked')) {
            // 获取工单id
            var workID = [];
            $.each($('input:checkbox:checked'), function() {
                workID.push($(this).val());
            });
            // 发送ajax请求,判断是否已经确认过
            $.getJSON('{:url("/administrative/workorder/judbatchconfirmation")}',{work_id:workID},function(data){
                // console.log(data);
                if (data.status == 0) {
                    top.layer.msg(data.message, {icon: 2});
                }
                if (data.status == 1) {
                    top.layer.confirm('是否确认工单？', {btn: ['确认','取消']}, function(){
                        // 发送ajax请求
                        $.getJSON('{:url("/administrative/workorder/batchconfirmation")}',{work_id:workID},function(data){
                            if (data.status == 0) {
                                top.layer.msg('工单确认失败', {icon: 2});
                                // 调用分页
                                Ajaxpage(1);
                            }else{
                                top.layer.msg('工单确认成功', {icon: 1});
                                // 调用分页
                                Ajaxpage(1);
                            }
                        });
                    });
                }
            });
        } else {
            $('#engineeringdepartment').modal('hide');
            layer.msg('你还未选中', {
                time: 1000,
                icon: 0
            });
        }
    }


    //指派工程部model
    function EngineeringDepartment() {
        if($('.selectthis').is(':checked')) {
            // 获取工单id
            var workID = [];
            $.each($('input:checkbox:checked'), function() {
                workID.push($(this).val());
            });
            // 发送ajax请求,判断是否已经指派工程部
            $.getJSON('{:url("/administrative/workorder/judgeworkoder")}',{work_id:workID,status:1},function(data){
               // console.log(data);
                if (data.status == 0) {
                    top.layer.msg(data.message, {icon: 2});
                }
                if (data.status == 1) {
                    top.layer.confirm('是否确认指派工程部？', {btn: ['确认','取消']}, function(){
                        // 发送ajax请求
                        $.getJSON('{:url("/administrative/workorder/assigndepartment")}',{work_id:workID},function(data){
                            if (data.status == 0) {
                                top.layer.msg('指派工程部失败', {icon: 2});
                                // 调用分页
                                Ajaxpage(1);
                            }else{
                                top.layer.msg('指派工程部成功', {icon: 1});
                                // 调用分页
                                Ajaxpage(1);
                            }
                        });
                    });
                }
            });

        } else {
            $('#engineeringdepartment').modal('hide');
            layer.msg('你还未选中', {
                time: 1000,
                icon: 0
            });
        }
    }


    // 工程人员指派弹窗页面
    function AssignEngineer() {
        if($('.selectthis').is(':checked')) {
                workID = [];
            $.each($('input:checkbox:checked'), function() {
                workID.push($(this).val());
            });
            $.getJSON("{:url('/administrative/workorder/judgeengineers')}",{work_order_id:workID},function(data){
                if (data.status == 0) {
                    top.layer.msg(data.message, {icon: 2});
                }
                if (data.status == 1) {
                    var html = '';
                    html +='<div id="userh">';
                    html +='<div class="modal-body">';
                    html +='<h2 class="fs14 col-666 mb10">选择工程人员</h2>';
                    html +='<p>';
                    html +='<input class="modalUser-input" type="text" name="username" placeholder="请输入姓名">';
                    html +='<input class="modalUser-input" type="text" name="telphone__" placeholder="请输入联系电话">';
                    html +='<input class="modalUser-input" type="text" name="id_card__" placeholder="请输入身份证号码">';
                    html +='<button onclick="searcheq()" class="btn btn-primary mr10 pl15 pr15 pt3 pb3">搜索</button>';
                    html +='<button onclick="engineeradd()" class="btn btn-primary pl15 pr15 pt3 pb3" ><i class="glyphicon glyphicon-plus"></i>&nbsp;&nbsp;新增工程人员</button>';
                    html +='</p>';
                    html +='<table class="table table-bordered mt20">';
                    html +='<thead>';
                    html +='<tr>';
                    html +='<th></th>';
                    html +='<th>头像</th>';
                    html +='<th>员工编号</th>';
                    html +='<th>姓名</th>';
                    html +='<th>联系电话</th>';
                    html +='<th>身份证号码</th>';
                    html +='<th>联系地址</th>';
                    html +='</tr>';
                    html +='</thead>';

                    html +='<tbody id="elist">';
                    html +='<tr>';
                    html +='<td><input type="radio" name="engineersId" value=""></td>';
                    //html +='<td><input type="checkbox" name="" value=""></td>';
                    html +='<td><img style="width: 30px; height: 30px;" src="__IMG__/Head_img.jpg"></td>';
                    html +='<td></td>';
                    html +='<td></td>';
                    html +='<td></td>';
                    html +='<td></td>';
                    html +='<td><p class="ellipsis" style="150px" title="重庆市渝北区中溉路13-13"></p></td>';
                    html +='</tr>';
                    html +='</tbody>';

                    html +='</table>';
                    html +='<div class="">';
                    html +='<div class=" clearfix">';
                    html +='<div class="clearfix" style="float:right;margin: 0 auto;">';
                    html +='<span class="fl mt5" id="count">共0条数据</span><span id="allpage"  class="fl  mr20 mt5"></span><span  class="fl" id="AjaxPage"></span>';
                    html +='</div>';
                    html +='<div class="spiner-example">';
                    html +='<div class="sk-spinner sk-spinner-three-bounce">';
                    html +='<div class="sk-bounce1"></div>';
                    html +='<div class="sk-bounce2"></div>';
                    html +='<div class="sk-bounce3"></div>';
                    html +='</div>';
                    html +='</div>';
                    html +='</div>';
                    html +='</div>';
                    html +='</div>';
                    html +='<div class="modal-footer t_center">';
                    html +='<button type="button" onclick="engineersqr()" class="btn btn-primary ml30 mr30 pl20 pr20 pt3 pb3">确认</button>';
                    html +='<button type="button" class="btn btn-default ml30 mr30 pl20 pr20 pt3 pb3" onclick="cancelmodel()">取消</button>';
                    html +='</div>';
                    html +='</div>';
                    //页面层
                    parent.layer.open({
                        title:'选择工程人员',
                        type: 1,
                        skin: 'layui-layer-rim', //加上边框
                        area: ['823px', '550px'], //宽高
                        content: html
                    });
                    Ajaxpages(1);
                }
			});
        }else {
            $('#AssignEngineer').modal('hide');
            top.layer.msg('你还未选中', {
                time: 1000,
                icon: 0
            });
        }
    }
    // 工程人员指派弹窗页面分页
    function Ajaxpages(curr) {
        // 搜索数据
        var username = $.trim(parent.$("input[name='username']").val());   // 姓名
        var telphone = $.trim(parent.$("input[name='telphone__']").val()); // 联系电话
        var id_card = $.trim(parent.$("input[name='id_card__']").val());   // 身份证号
		  $.getJSON("{:url('/administrative/workorder/getengineers')}",{
              page: curr || 1,
			  username: username,
			  telphone: telphone,
			  id_card: id_card
		  },function(data){
            parent.$(".spiner-example").css('display', 'none'); //数据加载完关闭动画
            if(data == '') {
                parent.$("#elist").html('<td colspan="20" style="padding-top:10px;padding-bottom:10px;font-size:16px;text-align:center">暂无数据</td>');
                parent.$('#count').html("共" + 0 + "条数据");
            } else {
                // 字符串拼接
                $("#elist").html('');
                var str = '';
                $.each(data,function(k,v){
                    str +='<tr>';
                    str +='<td><input type="radio" name="engineersId" value="'+v.engineers_id+'" data="'+v.engineers_name+'" number="'+v.engineers_number+'" telphone="'+v.engineers_phone+'"></td>';
                    //str +='<td><input type="checkbox" name="" value="'+v.engineers_id+'" data="'+v.engineers_name+'" number="'+v.engineers_number+'" telphone="'+v.engineers_phone+'"></td>';
                    str +='<td><img style="width: 30px; height: 30px;" src="__IMG__/Head_img.jpg"></td>';
                    str +='<td>' + v.engineers_number + '</td>';
                    str +='<td>' + v.engineers_name + '</td>';
                    str +='<td>' + v.engineers_phone + '</td>';
                    str +='<td>' + v.engineers_idcard + '</td>';
                    str +='<td><p class="ellipsis" style="150px" title="重庆市渝北区中溉路13-13">' + v.engineers_address + '</p></td>';
                    str +='</tr>';
                });
                // 将拼接的数据输出在页面
                parent.$("#elist").html(str);
                // 总的数据
                parent.$('#count').html("共" + data[0].count + "条数据");
                parent.laypage({
                    cont: parent.$('#AjaxPage'), //容器。值支持id名、原生dom对象，jquery对象,
                    pages: data[0].allPage, //总页数
                    skip: true, //是否开启跳页
                    skin: '#337ab7', //分页组件颜色
                    curr: curr || 1,
                    first: '首页', //若不显示，设置false即可
                    last: '尾页', //若不显示，设置false即可
                    groups: 3, //连续显示分页数
                    jump: function(obj, first) {
                        if(!first) {
                            Ajaxpages(obj.curr)
                        }
                        parent.$('#allpage').html('，第' + obj.curr + '页，共' + '<i>' + obj.pages + '</i>' + '页');
						inputlength();
                    }
                });
            }
        });
    }
	// 处理指派任务
    function Handle(engineers_id,engineers_number,engineers_name,engineers_phone){
        $.getJSON("{:url('/administrative/workorder/assignengineers')}",{
            work_order_id: workID,               // 工单id
            engineers_id: engineers_id,		  	 // 工程人员id
            engineers_number: engineers_number,  // 工程人员编号
            engineers_name: engineers_name,      // 工程人员姓名
            engineers_phone: engineers_phone	 // 工程人员电话
        },function(data){
            $("input[name='assignEngineers']").val(data.status);
        });
	}
	// 工单指派结果
	function AssignResult(){
        // 获取指派结果
        var status = $("input[name='assignEngineers']").val();
    	// 判断结果，并回应
        if (status == '0') {
            layer.msg('工单指派失败', {icon: 0});
        }else{
            layer.msg('工单指派成功', {icon: 1});
        }
	}






    //返回
	$('.backbtn').click(function() {
		$("#addNewworkorder_details").modal("hide");
		$("#addNewworkorder").modal("show");
	})
	//保存	
	$('.savebtn').click(function() {
		layer.msg('保存成功', {
			time: 1000,
			icon: 1
		})
	})
	//重置
	$('.resetbtn').click(function() {
		layer.msg('重置成功', {
			time: 1000,
			icon: 1
		})
		for(var i = 0; i < $('#addNewworkorder_details form').length; i++) {
			$('#addNewworkorder_details form')[i].reset();
		}
	})

	
	
	//确认
	function StateConfirm(){
		layer.msg('保存成功', {
			time: 1000,
			icon: 1
		});
		$(".stateWorkorder").hide();
	}
	//取消
	function CancelConfirm() {
		$(".stateWorkorder").hide();
	}
	
</script>